<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org" lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>花龙腾航 - 我的订单</title>
    <script src="https://cdn.tailwindcss.com"></script>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
    <style>
        @import url('https://fonts.googleapis.com/css2?family=Noto+Sans+SC:wght@400;500;700&display=swap');

        body {
            font-family: 'Noto Sans SC', sans-serif;
            background-color: #f8fafc;
        }

        .logo-text {
            background: linear-gradient(135deg, #3b82f6, #8b5cf6);
            -webkit-background-clip: text;
            background-clip: text;
            color: transparent;
            font-weight: 700;
        }

        .flight-card {
            transition: all 0.3s ease;
            box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
        }

        .flight-card:hover {
            transform: translateY(-2px);
            box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.1);
        }

        .status-badge {
            padding: 0.25rem 0.75rem;
            border-radius: 9999px;
            font-size: 0.75rem;
            font-weight: 600;
        }

        .tab-active {
            position: relative;
            color: #3b82f6;
            font-weight: 600;
        }

        .tab-active:after {
            content: "";
            position: absolute;
            bottom: -1px;
            left: 0;
            width: 100%;
            height: 3px;
            background: #3b82f6;
            border-radius: 3px 3px 0 0;
        }

        .airplane-icon {
            transform: rotate(90deg);
            color: #3b82f6;
        }

        .highlight {
            background-color: #FEF3C7;
            transition: background-color 0.3s;
        }

        .fade-in {
            animation: fadeIn 0.3s ease-in-out;
        }

        @keyframes fadeIn {
            from { opacity: 0; transform: translateY(10px); }
            to { opacity: 1; transform: translateY(0); }
        }

        .order-detail {
            max-height: 0;
            overflow: hidden;
            transition: max-height 0.3s ease-out;
        }

        .order-detail.open {
            max-height: 500px;
        }

        .progress-bar {
            height: 6px;
            border-radius: 3px;
            background-color: #e5e7eb;
        }

        .progress-fill {
            height: 100%;
            border-radius: 3px;
            background: linear-gradient(90deg, #3b82f6, #8b5cf6);
            transition: width 0.3s ease;
        }

        .date-picker {
            position: relative;
        }

        .date-picker input {
            padding-right: 2.5rem;
        }

        .date-picker i {
            position: absolute;
            right: 1rem;
            top: 50%;
            transform: translateY(-50%);
            pointer-events: none;
            color: #6b7280;
        }

        .search-box {
            position: relative;
        }

        .search-box i {
            position: absolute;
            left: 1rem;
            top: 50%;
            transform: translateY(-50%);
            color: #9ca3af;
        }

        .search-box input {
            padding-left: 2.5rem;
        }

        .user-avatar {
            background: linear-gradient(135deg, #3b82f6, #8b5cf6);
        }
        .dropdown-menu {
            display: none;
            position: absolute;
            right: 0;
            top: 100%;
            background-color: white;
            border-radius: 0.5rem;
            box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
            min-width: 200px;
            z-index: 10;
        }

        .dropdown-menu.open {
            display: block;
        }

        .dropdown-item {
            padding: 0.5rem 1rem;
            cursor: pointer;
            transition: background-color 0.2s;
        }

        .dropdown-item:hover {
            background-color: #f3f4f6;
        }

        /* Modal Styles */
        .modal {
            display: none;
            position: fixed;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            background-color: rgba(0, 0, 0, 0.5);
            z-index: 100;
            justify-content: center;
            align-items: center;
        }

        .modal.open {
            display: flex;
        }

        .modal-content {
            background-color: white;
            border-radius: 0.5rem;
            width: 90%;
            max-width: 500px;
            animation: modalFadeIn 0.3s ease-out;
        }

        @keyframes modalFadeIn {
            from {
                opacity: 0;
                transform: translateY(-20px);
            }
            to {
                opacity: 1;
                transform: translateY(0);
            }
        }
    </style>
</head>
<body>
<!-- Header -->
<header class="bg-white shadow-sm sticky top-0 z-10">
    <div class="container mx-auto px-4 py-4 flex justify-between items-center">
        <div class="flex items-center space-x-2">
            <i class="fas fa-plane text-3xl text-blue-500"></i>
            <h1 class="text-2xl font-bold logo-text">花龙腾航</h1>
        </div>
        <nav class="hidden md:flex space-x-6">
            <a href="user_index" class="text-gray-600 hover:text-blue-500">首页</a>
            <a href="user_flight_search" class="text-gray-600 hover:text-blue-500">航班查询</a>
            <a href="#" class="text-blue-500 font-medium">我的订单</a>
            <a href="user_ticket" class="text-gray-600 hover:text-blue-500">我的机票</a>
            <a href="user_member_center" class="text-gray-600 hover:text-blue-500">会员中心</a>
        </nav>
        <div class="flex items-center space-x-4">
            <div class="flex items-center space-x-2 cursor-pointer group relative" id="user-menu">
                <div class="w-8 h-8 rounded-full user-avatar overflow-hidden">
                    <img th:if="${imageExists}" th:src="'static/images/'+${user.getU_id()}+'.jpg?version=' + ${#dates.createNow().time}" alt="用户头像" class="w-full h-full object-cover">
                    <img th:if="${!imageExists} and ${user.getSex()} == '女'" src="https://randomuser.me/api/portraits/women/44.jpg" alt="用户头像" class="w-full h-full object-cover">
                    <img th:if="${!imageExists} and ${user.getSex()} == '男'" src="https://randomuser.me/api/portraits/men/71.jpg" alt="用户头像" class="w-full h-full object-cover">
                </div>
                <span class="hidden md:inline text-gray-700 group-hover:text-blue-500" th:text="${user.getU_name()}">张先生</span>
                <div class="dropdown-menu" id="dropdown-menu">
                    <div class="dropdown-item" onclick="location.href='user_profile'">
                        <i class="fas fa-user-cog mr-2"></i> 个人主页
                    </div>
                    <div class="dropdown-item" onclick="location.href='user_account_manage'">
                        <i class="fas fa-cog mr-2"></i> 账号管理
                    </div>
                    <div class="border-t border-gray-200 my-1"></div>
                    <div class="dropdown-item text-red-500" onclick="location.href='user_logout'">
                        <i class="fas fa-sign-out-alt mr-2"></i> 退出登录
                    </div>
                </div>
            </div>
        </div>
    </div>
</header>

<!-- Main Content -->
<main class="container mx-auto px-4 py-8">
    <div class="flex flex-col md:flex-row gap-8">
        <!-- Sidebar -->
        <aside class="w-full md:w-64 bg-white rounded-xl shadow-sm p-6 h-fit sticky top-24">
            <div class="flex items-center space-x-3 mb-6">
                <div class="h-12 w-12 rounded-full user-avatar flex items-center justify-center text-white text-xl overflow-hidden">
                    <img th:if="${imageExists}" th:src="'static/images/'+${user.getU_id()}+'.jpg?version=' + ${#dates.createNow().time}" alt="用户头像" class="w-full h-full object-cover">
                    <img th:if="${!imageExists} and ${user.getSex()} == '女'" src="https://randomuser.me/api/portraits/women/44.jpg" alt="用户头像" class="w-full h-full object-cover">
                    <img th:if="${!imageExists} and ${user.getSex()} == '男'" src="https://randomuser.me/api/portraits/men/71.jpg" alt="用户头像" class="w-full h-full object-cover">
                </div>
                <div>
                    <h3 class="font-bold text-gray-800" th:text="${user.getU_name()}">张先生</h3>
                    <p class="text-xs text-gray-500" th:text="${user.getGrade()}">黄金会员</p>
                </div>
            </div>

            <nav class="space-y-1">
                <a href="user_profile" class="block px-4 py-2 rounded-lg text-gray-700 hover:bg-blue-50 hover:text-blue-600 transition">
                    <i class="fas fa-user mr-3 text-gray-400"></i> 个人资料
                </a>
                <a href="#" class="block px-4 py-2 rounded-lg bg-blue-50 text-blue-600 font-medium transition">
                    <i class="fas fa-ticket-alt mr-3 text-blue-500"></i> 我的订单
                </a>
                <a href="user_ticket" class="block px-4 py-2 rounded-lg text-gray-700 hover:bg-blue-50 hover:text-blue-600 transition">
                    <i class="fas fa-ticket mr-3 text-gray-400"></i> 我的机票
                </a>
                <a href="user_member_center" class="block px-4 py-2 rounded-lg text-gray-700 hover:bg-blue-50 hover:text-blue-600 transition">
                    <i class="fas fa-crown mr-3 text-gray-400"></i> 会员权益
                </a>
                <a href="user_account_manage" class="block px-4 py-2 rounded-lg text-gray-700 hover:bg-blue-50 hover:text-blue-600 transition">
                    <i class="fas fa-cog mr-3 text-gray-400"></i> 账户设置
                </a>
            </nav>
        </aside>

        <!-- Order List -->
        <div class="flex-1">
            <div class="bg-white rounded-xl shadow-sm overflow-hidden fade-in">
                <div class="p-6 border-b border-gray-100">
                    <h2 class="text-xl font-bold text-gray-800 mb-2">我的订单</h2>
                    <p class="text-sm text-gray-500">查看和管理您的所有航班订单</p>
                    <p th:if="${order_operation_failure}" style="color: red">操作失败，请重新再试！</p>
                    <p th:if="${no_cancel}" style="color: red">距离航班起飞时间不足30分钟，无法取消订单！</p>
                </div>

                <!-- Tabs -->
                <div class="border-b border-gray-200 px-6">
                    <div class="flex space-x-8 overflow-x-auto">
                        <button onclick="filterOrders('all')" class="pb-3 px-1 tab-active" id="tab-all">
                            全部订单 <span id="all-count" class="ml-1 text-xs font-normal bg-blue-100 text-blue-600 px-2 py-0.5 rounded-full" th:text="${allOrderCounts}">15</span>
                        </button>
                        <button onclick="filterOrders('unpaid')" class="pb-3 px-1 text-gray-500 hover:text-blue-500" id="tab-unpaid">
                            待支付 <span id="unpaid-count" class="ml-1 text-xs font-normal bg-gray-100 text-gray-600 px-2 py-0.5 rounded-full" th:text="${unpaidOrderCounts}">2</span>
                        </button>
                        <button onclick="filterOrders('paid')" class="pb-3 px-1 text-gray-500 hover:text-blue-500" id="tab-paid">
                            已支付 <span id="paid-count" class="ml-1 text-xs font-normal bg-gray-100 text-gray-600 px-2 py-0.5 rounded-full" th:text="${paidOrderCounts}">5</span>
                        </button>
                        <button onclick="filterOrders('completed')" class="pb-3 px-1 text-gray-500 hover:text-blue-500" id="tab-completed">
                            已完成 <span id="completed-count" class="ml-1 text-xs font-normal bg-gray-100 text-gray-600 px-2 py-0.5 rounded-full" th:text="${completedOrderCounts}">7</span>
                        </button>
                        <button onclick="filterOrders('cancelled')" class="pb-3 px-1 text-gray-500 hover:text-blue-500" id="tab-cancelled">
                            已取消 <span id="cancelled-count" class="ml-1 text-xs font-normal bg-gray-100 text-gray-600 px-2 py-0.5 rounded-full" th:text="${cancelledOrderCounts}">1</span>
                        </button>
                        <button onclick="filterOrders('refund')" class="pb-3 px-1 text-gray-500 hover:text-blue-500" id="tab-refund">
                            退款中 <span id="refund-count" class="ml-1 text-xs font-normal bg-gray-100 text-gray-600 px-2 py-0.5 rounded-full" th:text="${refundOrderCounts}">15</span>
                        </button>
                    </div>
                </div>

                <!-- Search and Filter -->
                <div class="p-6 border-b border-gray-100">
                    <div class="flex flex-col md:flex-row justify-between items-start md:items-center gap-4">
                        <div class="flex-1 flex flex-col md:flex-row gap-4">
                            <div class="search-box flex-1">
                                <i class="fas fa-search"></i>
                                <input type="text" id="searchInput" placeholder="搜索订单号、航班号或目的地..." class="w-full pl-10 pr-4 py-2 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-blue-500">
                            </div>

                            <div class="date-picker">
                                <input type="date" id="dateFilter" class="border border-gray-300 rounded-lg px-4 py-2 focus:ring-2 focus:ring-blue-500 focus:border-blue-500 bg-gray-50">
                                <i class="fas fa-calendar-alt"></i>
                            </div>
                        </div>

                        <div class="flex space-x-2 w-full md:w-auto">
                            <select id="statusFilter" class="border border-gray-300 rounded-lg px-3 py-2 focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-blue-500 bg-gray-50">
                                <option value="">所有状态</option>
                                <option value="unpaid">待支付</option>
                                <option value="paid">已支付</option>
                                <option value="completed">已完成</option>
                                <option value="cancelled">已取消</option>
                                <option value="refund">退款中</option>
                            </select>
                            <button class="bg-blue-500 hover:bg-blue-600 text-white px-4 py-2 rounded-lg flex items-center transition" onclick="applyFilters()">
                                <i class="fas fa-filter mr-2"></i> 筛选
                            </button>
                        </div>
                    </div>
                </div>

                <!-- Order List -->
                <div class="divide-y divide-gray-100" id="order-list">
                    <!-- Order items will be dynamically inserted here -->
                    <div th:each="order : ${orders}" class="flight-card bg-white transition duration-300">
                        <div class="p-6">
                            <div class="flex justify-between items-start">
                                <div>
                                    <div class="flex items-center space-x-3 mb-2">
                                        <span class="font-medium text-gray-700">订单号: <span th:text="${order.getOrder_id()}">HL20231115-001</span></span>
                                        <span class="text-gray-400">|</span>
                                        <!--span class="text-gray-500" th:text="${#dates.format(order.getDate(), 'yyyy年MM月dd日')}">2023年11月15日</span-->
                                        <span class="text-gray-500" th:text="'创建日期 '+${order.getDate()}">2023年11月15日</span>
                                    </div>
                                    <span th:classappend="${order.getStatus()} == 'unpaid' ? 'bg-yellow-100 text-yellow-800' :
                                        (${order.getStatus()} == 'paid' ? 'bg-green-100 text-green-800' :
                                        (${order.getStatus()} == 'completed' ? 'bg-blue-100 text-blue-800' :
                                        (${order.getStatus()} == 'cancelled' ? 'bg-red-100 text-red-800' :
                                        'bg-purple-100 text-purple-800')))"
                                          class="status-badge"
                                          th:text="${order.getStatusText()}">已支付
                                    </span>
                                </div>
                                <div class="text-right">
                                    <div class="text-2xl font-bold text-blue-600">¥<span th:text="${order.getPrice()}">1280</span></div>
                                    <div class="text-sm text-gray-500"><span th:text="${order.getPassengers()}">2</span>位乘客</div>
                                </div>
                            </div>

                            <div class="mt-4 flex items-center justify-between">
                                <div class="flex items-center space-x-4">
                                    <div class="text-center">
                                        <div class="text-xl font-bold" th:text="${#strings.substringBefore(order.getFrom(), ' ')}">北京</div>
                                        <div class="text-xs text-gray-500" th:text="${#strings.substringAfter(order.getFrom(), ' ')}">(PEK)</div>
                                    </div>
                                    <div class="flex flex-col items-center">
                                        <div class="text-sm text-gray-500" th:text="${order.getDeparture()}">08:30</div>
                                        <div class="my-1 airplane-icon">
                                            <i class="fas fa-plane"></i>
                                        </div>
                                        <div class="text-sm text-gray-500" th:text="${order.getArrival()}">10:45</div>
                                    </div>
                                    <div class="text-center">
                                        <div class="text-xl font-bold" th:text="${#strings.substringBefore(order.getTo(), ' ')}">上海</div>
                                        <div class="text-xs text-gray-500" th:text="${#strings.substringAfter(order.getTo(), ' ')}">(SHA)</div>
                                    </div>
                                </div>
                                <div class="text-sm text-gray-500">
                                    <i class="fas fa-plane-departure mr-1"></i> 航班号: <span th:text="${order.getFlightNo()}">HL888</span>
                                </div>
                            </div>

                            <div class="mt-4 flex justify-between items-center border-t border-gray-100 pt-4">
                                <div>
                                    <div th:if="${order.getStatus() == 'unpaid'}" class="text-xs text-yellow-600">
                                        <i class="fas fa-exclamation-circle mr-1"></i> 请在
                                        <!--span th:text="${#dates.format(order.getPaymentDeadline(), 'yyyy年MM月dd日')}">2023年11月12日</span> 前完成支付-->
                                        <span th:text="${order.getPaymentDeadline()}">2023年11月12日</span> 前完成支付
                                    </div>
                                    <div th:if="${order.getStatus() == 'paid'}" class="text-xs text-green-600">
                                        <i class="fas fa-check-circle mr-1"></i> 已支付
                                        <span th:text="${order.getPaymentDate()}">2023年11月10日 14:23</span>
                                    </div>
                                    <div th:if="${order.getStatus() == 'completed'}" class="text-xs text-blue-600">
                                        <i class="fas fa-check-circle mr-1"></i> 已完成飞行
                                    </div>
                                    <div th:if="${order.getStatus() == 'cancelled'}" class="text-xs text-red-600">
                                        <i class="fas fa-times-circle mr-1"></i> 已取消
                                        <span th:text="${order.getCancelDate()}">2023年11月28日 16:45</span>
                                    </div>
                                    <div th:if="${order.getStatus() == 'refund'}" class="text-xs text-purple-600">
                                        <i class="fas fa-spinner mr-1"></i> 退款处理中
                                        <span th:text="'申请于'+${order.getRefundDate()}">申请于2023年12月05日</span>
                                    </div>
                                </div>

                                <form id="orderForm" method="post" action="user_order_operation">
                                    <div class="flex space-x-2">
                                        <!-- 隐藏字段用于传递 ticketId & flightId -->
                                        <input type="hidden" name="orderId" id="orderIdInput">
                                        <input type="hidden" name="actionType" id="actionTypeInput">

                                        <button type="button"
                                                class="px-4 py-2 bg-red-500 hover:bg-red-600 text-white rounded-lg text-sm transition"
                                                th:if="${order.getStatusText() == '待支付'}"
                                                th:attr="data-order-id=${order.getId()}"
                                                onclick="handleOrderAction(this, 'cancel')">
                                            取消订单
                                        </button>
                                        <!--button type="button"
                                                class="px-4 py-2 bg-blue-500 hover:bg-blue-600 text-white rounded-lg text-sm transition"
                                                th:if="${order.getStatusText() == '待支付'}"
                                                th:attr="data-order-id=${order.getId()}"
                                                onclick="handleOrderAction(this, 'pay')">
                                            立即支付
                                        </button-->
                                        <button type="button"
                                                class="px-4 py-2 bg-blue-500 hover:bg-blue-600 text-white rounded-lg text-sm transition"
                                                th:if="${order.getStatusText() == '待支付'}"
                                                th:attr="data-order-id=${order.getId()}"
                                                onclick="showPaymentModal(this)">
                                            立即支付
                                        </button>

                                        <button type="button"
                                                class="px-4 py-2 bg-red-500 hover:bg-red-600 text-white rounded-lg text-sm transition"
                                                th:if="${order.getStatusText() == '已支付'}"
                                                th:attr="data-order-id=${order.getId()}"
                                                onclick="handleOrderAction(this, 'cancel')">
                                            取消订单
                                        </button>
                                        <button type="button"
                                                class="px-4 py-2 border border-gray-300 hover:bg-gray-50 rounded-lg text-sm transition"
                                                th:if="${order.getStatusText() == '已完成'}"
                                                th:attr="data-order-id=${order.getId()}"
                                                onclick="handleOrderAction(this, 'rebook')">
                                            再次预订
                                        </button>

                                        <a class="px-4 py-2 border border-gray-300 hover:bg-gray-50 rounded-lg text-sm transition flex items-center"
                                           th:href="'user_order_check?o_id='+${order.getId()}+'&f_id='+${order.getFlightNo()}">
                                            <span>订单详情</span>
                                        </a>
                                    </div>
                                </form>
                            </div>
                        </div>
                    </div>
                </div>

                <!-- Empty State -->
                <div id="empty-state" class="hidden p-12 text-center">
                    <i class="fas fa-ticket-alt text-4xl text-gray-300 mb-4"></i>
                    <h3 class="text-lg font-medium text-gray-700">没有找到符合条件的订单</h3>
                    <p class="text-gray-500 mt-1">请尝试修改筛选条件或<a href="#" class="text-blue-500 hover:underline">预订新航班</a></p>
                </div>

                <!-- Pagination -->
                <div class="p-6 border-t border-gray-200 flex flex-col md:flex-row justify-between items-center gap-4">
                    <div class="text-sm text-gray-600">
                        显示 <span id="startItem" class="font-medium">1</span> 到 <span id="endItem" class="font-medium">5</span> 条，共 <span id="totalItems" class="font-medium">5</span> 条订单
                    </div>
                    <div class="flex items-center space-x-4">
                        <div class="flex items-center space-x-2">
                            <button id="prevPage" class="px-3 py-1.5 border border-gray-300 rounded-lg bg-white text-gray-700 hover:bg-gray-50 disabled:opacity-50 disabled:cursor-not-allowed flex items-center transition" disabled>
                                <i class="fas fa-chevron-left mr-1 text-xs"></i>
                                <span>上一页</span>
                            </button>
                            <div id="pageNumbers" class="flex space-x-1">
                                <button class="px-3 py-1 rounded-lg text-sm font-medium bg-blue-600 text-white">1</button>
                            </div>
                            <button id="nextPage" class="px-3 py-1.5 border border-gray-300 rounded-lg bg-white text-gray-700 hover:bg-gray-50 flex items-center transition disabled:opacity-50 disabled:cursor-not-allowed" disabled>
                                <span>下一页</span>
                                <i class="fas fa-chevron-right ml-1 text-xs"></i>
                            </button>
                        </div>
                        <div class="flex items-center space-x-2">
                            <span class="text-sm text-gray-600">每页显示</span>
                            <select id="pageSizeSelect" class="border border-gray-300 rounded-lg px-3 py-1.5 focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-blue-500 bg-gray-50 text-sm">
                                <option value="5">5条</option>
                                <option value="10">10条</option>
                                <option value="15">15条</option>
                                <option value="20">20条</option>
                            </select>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</main>


<!-- 支付方式选择模态框 -->
<div class="modal" id="paymentModal">
    <div class="modal-content">
        <div class="p-6 border-b border-gray-200 flex justify-between items-center">
            <h3 class="text-lg font-medium text-gray-800">请选择支付方式</h3>
            <button class="text-gray-400 hover:text-gray-500" onclick="closeModal('paymentModal')">
                <i class="fas fa-times"></i>
            </button>
        </div>

        <!-- 显示航班信息 -->
        <p id="flightToReschedule" class="text-center text-gray-600 mt-2 mb-4"></p>

        <div class="p-6">
            <div class="text-center mb-6">
                <p class="text-gray-700">请在下方选择您的支付方式：</p>
            </div>

            <!-- 支付方式选项 -->
            <div class="flex flex-col space-y-4">
                <label class="flex items-center space-x-3 p-3 border rounded-lg cursor-pointer hover:bg-gray-50">
                    <div class="h-10 w-10 bg-blue-100 rounded-full flex items-center justify-center mr-3">
                        <i class="fab fa-alipay text-blue-600 text-xl"></i>
                    </div>
                    <span>支付宝</span>
                    <input type="radio" name="paymentMethod" value="alipay" class="form-radio h-5 w-5 text-blue-600">
                </label>

                <label class="flex items-center space-x-3 p-3 border rounded-lg cursor-pointer hover:bg-gray-50">
                    <div class="h-10 w-10 bg-green-100 rounded-full flex items-center justify-center mr-3">
                        <i class="fab fa-weixin text-green-600 text-xl"></i>
                    </div>
                    <span>微信支付</span>
                    <input type="radio" name="paymentMethod" value="wechat" class="form-radio h-5 w-5 text-blue-600">
                </label>

                <label class="flex items-center space-x-3 p-3 border rounded-lg cursor-pointer hover:bg-gray-50">
                    <div class="h-10 w-10 bg-red-100 rounded-full flex items-center justify-center mr-3">
                        <i class="fas fa-credit-card text-red-600 text-xl"></i>
                    </div>
                    <span>银联支付</span>
                    <input type="radio" name="paymentMethod" value="unionpay" class="form-radio h-5 w-5 text-blue-600">
                </label>
            </div>

            <!-- 按钮 -->
            <div class="flex justify-center space-x-3 mt-6">
                <button type="button" class="px-4 py-2 border border-gray-300 rounded-lg text-gray-700 hover:bg-gray-50 transition" onclick="closeModal('paymentModal')">
                    取消
                </button>
                <button type="button" class="px-4 py-2 bg-blue-600 hover:bg-blue-700 text-white rounded-lg transition" onclick="submitRescheduleWithPayment()">
                    确认支付
                </button>
            </div>
        </div>
    </div>
</div>


<!-- Footer -->
<footer class="bg-gray-50 mt-12">
    <div class="container mx-auto px-4 py-8">
        <div class="grid grid-cols-1 md:grid-cols-4 gap-8">
            <div>
                <div class="flex items-center space-x-2 mb-4">
                    <i class="fas fa-plane text-2xl text-blue-500"></i>
                    <h3 class="text-xl font-bold logo-text">花龙腾航</h3>
                </div>
                <p class="text-gray-600 text-sm">花龙腾航，让您的每一次飞行都成为美好回忆。我们致力于提供安全、舒适、便捷的航空服务。</p>
            </div>
            <div>
                <h4 class="font-bold text-gray-800 mb-4">关于我们</h4>
                <ul class="space-y-2 text-sm text-gray-600">
                    <li><a href="public_company_profile" class="hover:text-blue-500 transition">公司简介</a></li>
                    <li><a href="public_company_profile" class="hover:text-blue-500 transition">企业文化</a></li>
                    <li><a href="public_company_profile" class="hover:text-blue-500 transition">发展历程</a></li>
                    <li><a href="public_job_posting" class="hover:text-blue-500 transition">招贤纳士</a></li>
                </ul>
            </div>
            <div>
                <h4 class="font-bold text-gray-800 mb-4">帮助中心</h4>
                <ul class="space-y-2 text-sm text-gray-600">
                    <li><a href="public_faq" class="hover:text-blue-500 transition">常见问题</a></li>
                    <li><a href="public_baggage_regulations" class="hover:text-blue-500 transition">行李规定</a></li>
                    <li><a href="public_company_profile" class="hover:text-blue-500 transition">航班动态</a></li>
                    <li><a href="public_callus" class="hover:text-blue-500 transition">联系客服</a></li>
                </ul>
            </div>
            <div>
                <h4 class="font-bold text-gray-800 mb-4">联系我们</h4>
                <ul class="space-y-2 text-sm text-gray-600">
                    <li class="flex items-center"><i class="fas fa-phone-alt mr-2 text-blue-500"></i> 客服热线: 19976338635</li>
                    <li class="flex items-center"><i class="fas fa-envelope mr-2 text-blue-500"></i> ganshenghao888@qq.com</li>
                    <li class="flex items-center"><i class="fas fa-map-marker-alt mr-2 text-blue-500"></i> 广东省广州市天河区华南农业大学</li>
                </ul>
                <div class="flex space-x-4 mt-4">
                    <a href="https://weixin.com" class="h-8 w-8 rounded-full bg-blue-100 flex items-center justify-center text-blue-500 hover:bg-blue-200 transition">
                        <i class="fab fa-weixin"></i>
                    </a>
                    <a href="https://weibo.com" class="h-8 w-8 rounded-full bg-blue-100 flex items-center justify-center text-blue-500 hover:bg-blue-200 transition">
                        <i class="fab fa-weibo"></i>
                    </a>
                    <a href="https://qq.com" class="h-8 w-8 rounded-full bg-blue-100 flex items-center justify-center text-blue-500 hover:bg-blue-200 transition">
                        <i class="fab fa-qq"></i>
                    </a>
                </div>
            </div>
        </div>
        <div class="border-t border-gray-200 mt-8 pt-6 text-center text-sm text-gray-500">
            <p>© 2025 花龙腾航航空公司 版权所有 | 京ICP备12345678号</p>
        </div>
    </div>
</footer>

<script>
    function handleOrderAction(button, actionType) {
        const form = button.closest("form");
        const orderId = button.getAttribute("data-order-id");

        form.orderId.value = orderId;
        form.actionType.value = actionType;

        if (confirm(`确定要${getActionName(actionType)}吗？`)) {
            form.submit();
        }
    }

    // 支付按钮单独处理
    function showPaymentModal(button) {
        const form = button.closest("form");
        const orderId = button.getAttribute("data-order-id");

        // 设置当前表单到全局变量中以便后续使用
        window.currentForm = form;
        window.currentOrderId = orderId;

        document.getElementById("paymentModal").classList.add("open");
    }

    function submitRescheduleWithPayment() {
        const paymentMethod = document.querySelector('input[name="paymentMethod"]:checked');
        if (!paymentMethod) {
            alert("请选择一种支付方式！");
            return;
        }

        const form = window.currentForm;
        form.orderId.value = window.currentOrderId;
        form.actionType.value = "pay";

        const input = document.createElement("input");
        input.type = "hidden";
        input.name = "paymentMethod";
        input.value = paymentMethod.value;
        form.appendChild(input);

        form.submit();
    }

    function closeModal(modalId) {
        const modal = document.getElementById(modalId);
        if (modal) {
            modal.classList.remove('open');
        }
    }

</script>

<script>
    // Current page and page size
    let currentPage = 1;
    let pageSize = parseInt(localStorage.getItem('pageSize')) || 5;
    let currentFilter = 'all';
    let allOrders = Array.from(document.querySelectorAll('.flight-card'));

    // Variables for cancel order modal
    let currentOrderId = '';
    let currentFlightNo = '';

    // DOM elements
    const orderList = document.getElementById('order-list');
    const emptyState = document.getElementById('empty-state');
    const searchInput = document.getElementById('searchInput');
    const dateFilter = document.getElementById('dateFilter');
    const statusFilter = document.getElementById('statusFilter');
    const prevPageBtn = document.getElementById('prevPage');
    const nextPageBtn = document.getElementById('nextPage');
    const pageNumbers = document.getElementById('pageNumbers');
    const startItem = document.getElementById('startItem');
    const endItem = document.getElementById('endItem');
    const totalItems = document.getElementById('totalItems');
    const pageSizeSelect = document.getElementById('pageSizeSelect');
    const cancelModal = document.getElementById('cancelModal');

    // Initialize page
    function init() {
        // Set the saved page size
        pageSizeSelect.value = pageSize;
        applyFilters();
        addEventListeners();
    }

    // 设置票据信息和操作类型
    function handleOrderAction(button, actionType) {
        const orderId = button.getAttribute('data-order-id');

        const actionMap = {
            cancel: "取消",
            pay: "支付",
            rebook: "再次预定"
        };

        const actionName = actionMap[actionType] || "执行此操作";

        if (confirm(`确定要${actionName}吗？`)) {
            // 设置隐藏字段并提交表单
            document.getElementById('orderIdInput').value = orderId;
            document.getElementById('actionTypeInput').value = actionType;

            document.getElementById('orderForm').submit();
        } else {
            return false;
        }
    }

    // Filter orders by status
    function filterOrders(status) {
        currentFilter = status;

        // Update active tab
        document.querySelectorAll('[id^="tab-"]').forEach(tab => {
            tab.classList.remove('tab-active');
            tab.classList.add('text-gray-500');
        });
        const activeTab = document.getElementById(`tab-${status}`);
        activeTab.classList.add('tab-active');
        activeTab.classList.remove('text-gray-500');

        // Apply filters
        applyFilters();
    }

    // Apply all filters (status, search, date)
    function applyFilters() {
        const searchTerm = searchInput.value.toLowerCase();
        const selectedDate = dateFilter.value;
        const selectedStatus = statusFilter.value;

        // Get all order elements
        allOrders = Array.from(document.querySelectorAll('.flight-card'));

        let visibleOrders = allOrders.filter(order => {
            const orderId = order.querySelector('.font-medium').textContent.toLowerCase();
            const flightNo = order.querySelector('.text-sm.text-gray-500:last-child span').textContent.toLowerCase();
            const fromCity = order.querySelector('.text-center:first-child .text-xl').textContent.toLowerCase();
            const toCity = order.querySelector('.text-center:last-child .text-xl').textContent.toLowerCase();
            const orderDate = order.querySelector('.text-gray-500').textContent;
            const status = order.querySelector('.status-badge').textContent;

            // Status filter
            const matchesStatus = currentFilter === 'all' ||
                (currentFilter === 'unpaid' && status === '待支付') ||
                (currentFilter === 'paid' && status === '已支付') ||
                (currentFilter === 'completed' && status === '已完成') ||
                (currentFilter === 'cancelled' && status === '已取消') ||
                (currentFilter === 'refund' && status === '退款中');

            // Additional status filter from dropdown
            const matchesAdditionalStatus = selectedStatus === '' ||
                (selectedStatus === 'unpaid' && status === '待支付') ||
                (selectedStatus === 'paid' && status === '已支付') ||
                (selectedStatus === 'completed' && status === '已完成') ||
                (selectedStatus === 'cancelled' && status === '已取消') ||
                (selectedStatus === 'refund' && status === '退款中');

            // Search term - matches order ID, flight number, departure or arrival city
            const matchesSearch = searchTerm === '' ||
                orderId.includes(searchTerm) ||
                flightNo.includes(searchTerm) ||
                fromCity.includes(searchTerm) ||
                toCity.includes(searchTerm);

            // Date filter
            const formattedTicketDate = orderDate.replace(/(\d{4})年(\d{2})月(\d{2})日/, '$1-$2-$3');
            const matchesDate = selectedDate === '' ||
                formattedTicketDate.includes(selectedDate);

            return matchesStatus && matchesAdditionalStatus && matchesSearch && matchesDate;
        });

        // Update total items count
        totalItems.textContent = visibleOrders.length;

        // Show empty state if no orders match
        if (visibleOrders.length === 0) {
            emptyState.classList.remove('hidden');
        } else {
            emptyState.classList.add('hidden');
        }

        // Reset to first page when filters change
        currentPage = 1;
        renderPagination(visibleOrders);
    }

    // Change page size
    function changePageSize(newSize) {
        pageSize = parseInt(newSize);
        // Save to localStorage
        localStorage.setItem('pageSize', pageSize);
        currentPage = 1;
        applyFilters();
    }

    // Pay order (simulated)
    function payOrder(orderId) {
        // In a real application, this would make an AJAX call to the backend
        if (confirm(`确定要支付订单 ${orderId} 吗？`)) {
            alert(`订单 ${orderId} 支付成功！`);
            // Reload the page to reflect changes
            window.location.reload();
        }
    }

    // Render pagination controls
    function renderPagination(visibleOrders) {
        const totalPages = Math.ceil(visibleOrders.length / pageSize);

        // Update prev/next buttons
        prevPageBtn.disabled = currentPage === 1;
        nextPageBtn.disabled = currentPage === totalPages || totalPages === 0;

        // Clear page numbers
        pageNumbers.innerHTML = '';

        // Calculate range of pages to show
        let startPage = Math.max(1, currentPage - 2);
        let endPage = Math.min(totalPages, currentPage + 2);

        // Ensure we show 5 pages if possible
        if (endPage - startPage < 4) {
            if (currentPage < totalPages / 2) {
                endPage = Math.min(startPage + 4, totalPages);
            } else {
                startPage = Math.max(endPage - 4, 1);
            }
        }

        // Add first page button
        if (startPage > 1) {
            addPageButton(1, visibleOrders);
            if (startPage > 2) {
                const ellipsis = document.createElement('span');
                ellipsis.className = 'px-3 py-1';
                ellipsis.textContent = '...';
                pageNumbers.appendChild(ellipsis);
            }
        }

        // Add page buttons
        for (let i = startPage; i <= endPage; i++) {
            addPageButton(i, visibleOrders);
        }

        // Add last page button
        if (endPage < totalPages) {
            if (endPage < totalPages - 1) {
                const ellipsis = document.createElement('span');
                ellipsis.className = 'px-3 py-1';
                ellipsis.textContent = '...';
                pageNumbers.appendChild(ellipsis);
            }
            addPageButton(totalPages, visibleOrders);
        }

        // Update pagination info
        const startIndex = (currentPage - 1) * pageSize;
        const endIndex = Math.min(startIndex + pageSize, visibleOrders.length);

        startItem.textContent = startIndex + 1;
        endItem.textContent = endIndex;
        totalItems.textContent = visibleOrders.length;

        // Show/hide orders based on current page
        allOrders.forEach(order => order.style.display = 'none');
        visibleOrders.forEach((order, index) => {
            if (index >= startIndex && index < endIndex) {
                order.style.display = '';
            }
        });
    }

    // Add a page button
    function addPageButton(page, visibleOrders) {
        const button = document.createElement('button');
        button.className = `px-3 py-1 rounded-lg text-sm font-medium ${currentPage === page ? 'bg-blue-600 text-white' : 'bg-white text-gray-700 hover:bg-gray-50'}`;
        button.textContent = page;
        button.addEventListener('click', () => {
            currentPage = page;
            renderPagination(visibleOrders);
            window.scrollTo({ top: 0, behavior: 'smooth' });
        });
        pageNumbers.appendChild(button);
    }

    // Add event listeners
    function addEventListeners() {
        // Search input
        searchInput.addEventListener('input', () => {
            applyFilters();
        });

        // Date filter
        dateFilter.addEventListener('change', () => {
            applyFilters();
        });

        // Status filter
        statusFilter.addEventListener('change', () => {
            applyFilters();
        });

        // Previous page
        prevPageBtn.addEventListener('click', () => {
            if (currentPage > 1) {
                currentPage--;
                applyFilters();
                window.scrollTo({ top: 0, behavior: 'smooth' });
            }
        });

        // Next page
        nextPageBtn.addEventListener('click', () => {
            const visibleOrders = allOrders.filter(order => order.style.display !== 'none');
            const totalPages = Math.ceil(visibleOrders.length / pageSize);

            if (currentPage < totalPages) {
                currentPage++;
                applyFilters();
                window.scrollTo({ top: 0, behavior: 'smooth' });
            }
        });

        // Page size selector
        pageSizeSelect.addEventListener('change', (e) => {
            changePageSize(e.target.value);
        });
    }

    // Initialize the page
    document.addEventListener('DOMContentLoaded', init);

    // Toggle user dropdown menu
    document.getElementById('user-menu').addEventListener('click', function(event) {
        event.stopPropagation(); // 防止点击事件冒泡
        document.getElementById('dropdown-menu').classList.toggle('open');
    });

    // Close dropdown when clicking outside
    document.addEventListener('click', function(event) {
        const dropdown = document.getElementById('dropdown-menu');
        const userMenu = document.getElementById('user-menu');

        if (!userMenu.contains(event.target) && !dropdown.contains(event.target)) {
            dropdown.classList.remove('open');
        }
    });
</script>
</body>
</html>